
const app = getApp();
const api = app.apiInstance
Page({  
  data: {
    dataItem:{},
    suffix:''
  },
  async onShow(){

  },
  async loadData(id){

    const res = await api.get(`/v1/openApi/laws/detail/${id}`);

    //const suffixList =  res.data.files[0]?.fileNewName?.split(".");
    const suffix = ''

    this.setData({
      dataItem:res.data,
      suffix :suffix
    })
    
  },

  onLoad(options) {
    this.loadData(options.id);
  },


  gotoWebView(e){

    const url = e.currentTarget.dataset.url
    wx.setClipboardData({  
      data: url,  
      success(res) {  
        wx.showToast({  
          title: '复制链接成功，请打开浏览器并粘贴链接',  
          icon: 'none',  
          duration: 3000  
        });  
      }  
    });
   
    // wx.navigateTo({
    //   url: url
    // })

    // wx.navigateTo({
    //   url: `/pages/comWebView/comWebView?url=${encodeURIComponent(url)}&closeBtn=false`
    // });
  },


  openFuJian(e){
    const fileName = e.currentTarget.dataset.item.fileNewName
    const url = e.currentTarget.dataset.item.originalFileName
    const suffix = this.data.suffix
    const imageList = ['JPG','PNG','jpeg','jpg','png']
    if(imageList.includes(suffix)){
      console.log(`${app.globalData.fileUrl}/${url}`)
      wx.previewImage({
        current: `${app.globalData.fileUrl}/${url}`, // 当前显示图片的链接/路径
        urls: [`${app.globalData.fileUrl}/${url}`]
      })
    }
    else{
      console.log('1111',222)
      wx.downloadFile({
        url: `${app.globalData.fileUrl}/common/download/resource?resource=${fileName}`,
        success:(res)=>{
          console.log('res',res)

          wx.openDocument({
              filePath: `${res.tempFilePath}`,
              fileType:suffix.toLowerCase(),
              showMenu: false, //右上角是否有可以转发分享的功能
              success: function(res) {
                  console.log('res',res)
              },
              fail: function(err) {
                console.log('err',err)
              }
          });

        }
      })

      
    }
  },
 

})
